<template>
  <div class="mod-config">
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      style="width: 100%;"
    >
      <el-table-column header-align="center" align="center" label="表单">
        <template slot-scope="scope">
          {{ scope.row.formId === 1?'默认表单':'' }}
          {{ scope.row.formId === 2?'购买页':'' }}
          {{ scope.row.formId === 3?'二维码':'' }}
        </template>
      </el-table-column>
      <el-table-column prop="groupName" header-align="center" align="center" label="群库名称"></el-table-column>
      <el-table-column prop="groupUrl" header-align="center" align="center" label="链接"></el-table-column>
      <el-table-column fixed="right" header-align="center" align="center" label="操作" width="150px">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="addChannel(scope.row)">编辑</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper"
    ></el-pagination>

    <!--添加渠道s-->
    <el-dialog
      :close-on-click-modal="false"
      :visible.sync="visible1"
      title="群库链接编辑"
    >
      <el-form
        :model="dataForm1"
        ref="dataForm1"
        label-width="150px"
        :rules="rules"
      >
        <el-form-item label="群库链接:" prop="groupUrl">
          <el-input v-model="dataForm1.groupUrl"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="visible1 = false">取消</el-button>
        <el-button type="primary" @click="channelForm">确定</el-button>
      </span>
    </el-dialog>
    <!--添加渠道e-->

  </div>
</template>

<script>
  export default {
    data() {
      return {
        visibleIntegralList: false,
        dataForm: {},
        dataForm1: {},
        rules: {
          groupUrl: [
            { required: true, message: '请输入渠道名称', trigger: 'blur' }
          ]
        },
        zanConfig: 0,
        visible1: false,
        dataList: [],
        dataListLoading: false,
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0
      }
    },
    activated() {
      this.getDataList()
    },
    methods: {
      search() {
        this.pageIndex = 1
        this.getDataList()
      },
      // 获取数据列表
      getDataList() {
        this.dataListLoading = true
        this.dataForm.page = this.pageIndex
        this.dataForm.limit = this.pageSize
        this.$http({
          url: this.$http.adornUrl('/market/marketsurveygroupconfig/list'),
          method: 'get',
          params: this.$http.adornParams(this.dataForm)
        }).then(({ data }) => {
          if (data && data.code === 0) {
            this.dataList = data.page.list
            this.totalPage = data.page.totalCount
          } else {
            this.dataList = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        })
      },
      addChannel(channelInfo) {
        this.dataForm1 = channelInfo
        this.visible1 = true
      },
      channelForm() {
        this.$refs['dataForm1'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl('/market/marketsurveygroupconfig/update'),
              method: 'post',
              data: this.$http.adornData(this.dataForm1)
            }).then(({data}) => {
              if(data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible1 = false
                    this.getDataList()
                  }
                });
              }
            })
          }
        })
      },
      // 每页数
      sizeChangeHandle(val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle(val) {
        this.pageIndex = val
        this.getDataList()
      }
    }
  }
</script>
<style>
  .margin_10{
    margin-bottom: 10px;
  }
  .text_r{
    text-align: right;
    padding-right: 15px;
  }
  .inineBlock{
    display: inline-block;
  }
  img{
    width: 100%;
    height: auto;
  }
</style>
